<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['ischecklogin']=$this->model('member')->checklogin('','','','',true);
$shopset=$this->plugin_setting('shopset');
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('basic');
	$return['list']=array();
	set_html('title','商品评论');
	exi($return);
}
if($_RQ['op']=='commentorder'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}	
	$order_goods=pdo_getall('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$id));   
    if($order_goods){
		foreach($order_goods as $k=>&$item){
			$goodinfo=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']),array('title','merchid','subtitle','image','price'));          //商品信息
			$goodinfo['image']=tomedia($goodinfo['image']);
			if($goodinfo['merchid']){
				$item['merch']=pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$goodinfo['merchid']),array('id','merchname'));
			}
			$item=array_merge($goodinfo,$item);
			if($item['optionid']){
				$specs=pdo_getcolumn('jy_weishop_goods_option',array('id'=>$optionid),'specs');
				$specs=explode("_",$specs);
				foreach($specs as &$spec){
					$spec=pdo_getcolumn('jy_weishop_goods_spec_item',array('id'=>$spec),'title');
				}
				$item['optiontitle']=implode("，",$specs);
			}
		}
	}
	$comment=$this->pdo_get('comments',array('orderid'=>$id,'uniacid'=>$_SESSION['uniacid']));		
	if($comment){
				$item['post']=$comment;
				if($comment['createtime']){
					$comment_changedays=1;
					$endpingjiatime = $comment['createtime'] + $comment_changedays*24*3600;
					if($endpingjiatime<TIMESTAMP){
						$return['nocanping']=1;
					}
				}
				if($comment['show']==1){
					$return['nocanping']=1;
				}
	}else{
		$item['post']=array(
			'orderid'=>$id,
			'star'=>5,
		);
	}
	$return['goods_list']=$order_goods;
	exi($return);
}

if($_RQ['op']=='submit'){
	$postdata=get_postdata();
	$data=array(
		'content'=>$postdata['content'],
		'star'=>intval($postdata['star']),
	);
	$comment_id=$this->pdo_getcolumn('comments',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>intval($postdata['orderid'])),'id');
	if($comment_id){
		if($postdata['show']==1){
			exi('该评价已生效显示，不可修改！','error','goback');
		}
		$this->pdo_update('comments',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$comment_id));
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'orderid'=>intval($postdata['orderid']),
			'createtime'=>TIMESTAMP,
		);
		$data=array_merge($insert,$data);
		$this->pdo_insert('comments',$data);
	}
	exi('评价成功！','','goback');
}
?>